<?php
header("Content-Type:text/plain;charset=utf-8");

$staff=array
(
	array("name"=>"person1","number"=>"101","sex"=>"boy","job"=>"manager"),
	array("name"=>"person2","number"=>"102","sex"=>"boy","job"=>"developer"),
	array("name"=>"person3","number"=>"103","sex"=>"girl","job"=>"secretary"),
);

if ($_SERVER["REQUEST_METHOD"]=="GET"){
	search();
}elseif($_SERVER["REQUEST_METHOD"]=="POST"){
	create();	
}

function search(){
	if (!isset($_GET["number"])||empty($_GET["number"])){
		echo "parameter error!";
		return;
	}
	
	global $staff;
	
	$number = $_GET["number"];
	$result = "not found!";
	
	foreach ($staff as $value){
		if ($value["number"]==$number){
			$result="found! number:".$value["number"].", name:".$value["name"].", sex:".$value["sex"].", job:".$value["job"];
			break;
		}
	}
	
	echo $result;
}

function create(){
	if (!isset($_POST["name"]) || empty($_POST["name"])
		|| !isset($_POST["number"]) || empty($_POST["number"])
		|| !isset($_POST["sex"]) || empty($_POST["sex"])
		|| !isset($_POST["job"]) || empty($_POST["job"])){
		echo "parameters error. The Information is incomplete.";
		return;
	}
	
	echo "person: ".$_POST["name"]." saved succeed!";
}
?>